<template>
	<el-dialog
		title="添加管理员"
		width="50%"
		visible
		custom-class="add-model"
	>
		<el-form
			ref="form"
			:model="addForm"
			:rules="ADMIN_INFO"
			label-width="80px"
		>
			<el-form-item
				label="userId"
				prop="userId"
			>
				<el-input v-model="addForm.userId" />
			</el-form-item>
			<el-form-item
				label="真实姓名"
				prop="trueName"
			>
				<el-input v-model="addForm.trueName" />
			</el-form-item>
		</el-form>
		<span	slot="footer">
			<el-button @click="$emit('close')">取消</el-button>
			<el-button
				type="primary"
				@click="onclickAdd"
			>
				确定
			</el-button>
		</span>
	</el-dialog>
</template>

<script>
import { addAdmin } from '@admin/api/admin.js'
import { ADMIN_INFO } from '@admin/constants/rules'
export default {
  data() {
    return {
      ADMIN_INFO,
      addForm: {
        userId: '',
        trueName: '',
      },
    }
  },
  methods: {
    /**
     * 点击添加
     */
    onclickAdd() {
      this.$refs.form.validate(async(valid) => {
        if (valid) {
          await addAdmin(this.addForm)

          this.$emit('finish', this.addForm)
          this.$emit('close')
        }
      })
    },
  }
}
</script>
